

<?php
if ( $_SESSION['logged_in'] == FALSE ) redirect (base_url ());

/*
 * Add a new property to the system
 * 
 */
echo '<div id="contentfull">';
echo '<div id="forms">';
echo '<a href="'.$baseurl.'index.php/listprop"><img class="btnimg" src="'.$baseurl.'public/images/close.png" align="right" alt="close" border="0" /></a>';
$opt = array('name' => 'addprop', 'id' => 'addprop');
echo form_open($baseurl.'index.php/propertyadd/', $opt);
echo form_fieldset('<h2>   Add a new Property   </h2>');
//var_dump($property);
?>
 
<table>
    <tr>
        <td width="150px" >
<?php   echo form_label('Property Name *', 'pname'); 
        //echo form_error('Name'); 
        $namec = array('name' => 'pname', 
               'id' => 'pname',  
               'maxlength'   => '50',
               'value'       => $property['Name'],
              'style'       => 'width: 200px' ); ?>  </td>
        <td width="200px" ><?php echo form_input($namec); echo '<br>'.form_error('pname');?>       </td>
        <td width="150px" ><?php echo form_label('Area', 'area'); ?></td>
        <td width="200px" ><?php echo $property['area']['areaname']; ?> </td>
    </tr>
    
    <tr>
        <td> <?php echo form_label('Street', 'Street');  $level = array('name' => 'Street', 'id' => 'Street' );
      
        // This chunk of code only shows the streets in the area
       // var_dump($areas);
         $options = [];
         $options = array_merge($options, array('0' => 'Please select '));
         foreach($streets as $value)
        {
            $mid = $value['Street'] ;
            $t = array($mid => $value['Street']);
            $options = array_merge($options, $t); 
        }
        $sel = $property['street'];
        $js = 'onchange="setisect();"';
?> </td>
        <td> <?php echo form_dropdown('Street', $options, '', $js); echo '<br>'.form_error('Street'); ?> </td>
        <td> <?php echo form_label('Street Number *', 'roadnum'); $numberc = array('name' => 'roadnum', 
               'id' => 'roadnum',  
              'value'       => $property['roadnum'],
              'style'       => 'width: 60px'); ?>
 </td>
        <td> <?php echo form_input($numberc);echo '<br>'.form_error('roadnum'); ?> </td>
    </tr>
    
    <tr>
        <td> <?php echo form_label('Nearest Intersection *', 'intersect'); $intersectc = array('name' => 'intersect', 
               'id' => 'intersect',  
               'maxlength'   => '200',
              'value'       => $property['intersect'],
              'style'       => 'width: 200px' ); ?> </td>
        <td> <?php echo form_input($intersectc); echo '<br>'.form_error('intersect'); ?> </td>
        
        <td> <?php echo form_label('GPS Longitude', 'longitude');  
            $gpslongc = array('name' => 'longitude', 
               'id' => 'longitude',  
               'maxlength'   => '10',
               'value'       => $property['gps']['longitude'],
               'style'       => 'width: 60px'); ?>
        <td> <?php echo form_input($gpslongc); echo '<br>'.form_error('longitude'); ?> </td>
        
        <td> <?php echo form_label('GPS Latitude', 'latutude');
                $gpslatc = array('name' => 'latutude', 
               'id' => 'latutude',  
               'maxlength'   => '10',
               'value'       => $property['gps']['latutude'],
               'style'       => 'width: 60px');   ?>
        </td>
        <td> <?php echo form_input($gpslatc); echo '<br>'.form_error('latutude'); ?> </td>
    </tr>
    
    
        
      <tr>
        <td> <?php echo form_label('Owner', 'oid');  $level = array('name' => 'oid', 'id' => 'oid' );
        
        // This code allows for all areas to be displayed and the ones that are linked to be selected
//        $options = [];
//        foreach($areas as $value)
//        {
//            $mid = $value['id'] ;
//            $t = array($mid => $value['Area']);
//            $options = array_merge($options, $t); 
//        }
//      
//        $selected = [];
//        foreach ($data[0]['areas'] as $sel) {
//            $selected = array_merge($selected, $sel);
//        }

        // This chunk of code only shows the arears that are linked
         $options = [];
         //var_dump($owners);
         $options = array_merge($options, array('0' => 'Please select '));
         foreach($owners as $value)
        {
            $mid = $value['id'] ;
            $t = array($mid => $value['Name']);
            $options = array_merge($options, $t); 
        }
        $selected = $property['Owner']['oid'];
?> </td>
        <td> <?php echo form_dropdown('oid', $options, $selected); ?> </td>
           
        

    <tr>
        <td colspan="4" align="right" > <?php echo form_submit('save', 'Save'); echo form_reset('reset', 'Reset');?>  
        
    </tr>
</table>    
<?=form_fieldset_close()?>
<?=form_close(); ?>

</div> <!--content-->
</div> <!--login-->

<div id="getstreet" class="modalDialog">
	<div>
            <form name="secstr">
		<a href="#close" title="Close" class="close">X</a>
		<h4>Select the Second Street in the intersection</h4>
                <?php
                $options = [];
                 foreach($streets as $value)
                 {
                    $mid = $value['id'] ;
                    $t = array($mid => $value['Street']);
                    $options = array_merge($options, $t); 
                 }
                 $js = 'onchange="setsisect(); #close;"';
                 echo form_dropdown('isect2', $options, '', $js); ?> 
            </form>
            <a href="javascript:parent.closeIFrame();">close</a>
	</div>    
        
</div>

<script language="javascript" type="text/javascript">
    
function setisect() {
      var streetsel = document.addprop.Street;
      var street = streetsel[streetsel.selectedIndex].text;
      //alert(street);
      document.getElementById("intersect").value = street; 
    //  document.getElementById("intersect").innerHTML = street; 
    window.location.hash = 'getstreet';
}

function setsisect() {
     var sttsel =  document.secstr.isect2;
     var str = sttsel[sttsel.selectedIndex].text;
     document.getElementById("intersect").value = document.getElementById("intersect").value + " and " +str; 
    //  document.getElementById("intersect"
}
    
</script>    